using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;

namespace KPIS.GERP.Models.HRM
{
    [DataContract, Table("hrm_ps_time_att_monthly")]
    public class PsTimeAttendanceMonthly
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity), DataMember, Column("time_att_month_seq"), Display(Name = "TimeAttMonthId", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public int TimeAttMonthId { get; set; }

        [ForeignKey("Employee"), DataMember, Column("emp_seq"), Display(Name = "EmpId", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public int? EmpId { get; set; }

        [DataMember, Column("working_month"), Display(Name = "WorkingMonth", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public int? WorkingMonth { get; set; }

        [DataMember, Column("working_year"), Display(Name = "WorkingYear", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public int? WorkingYear { get; set; }

        [DataMember, Column("plan_working_day_count"), Display(Name = "PlanWorkingDayCount", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public int? PlanWorkingDayCount { get; set; }

        [DataMember, Column("actual_working_day_count"), Display(Name = "ActualWorkingDayCount", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public decimal? ActualWorkingDayCount { get; set; }

        [DataMember, Column("valid_absence_day_count"), Display(Name = "ValidAbsenceDayCount", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public decimal? ValidAbsenceDayCount { get; set; }

        [DataMember, Column("invalid_absence_day_count"), Display(Name = "InvalidAbsenceDayCount", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public decimal? InvalidAbsenceDayCount { get; set; }

        [DataMember, Column("late_day_count"), Display(Name = "LateDayCount", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public decimal? LateDayCount { get; set; }

        [DataMember, Column("not_working_day_count")]
        public decimal? NotWorkingDayCount { get; set; }

        [DataMember, Column("remarks"), Display(Name = "Remarks", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public string Remarks { get; set; }

        [DataMember, Column("record_status"), Display(Name = "RecordStatus", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public string RecordStatus { get; set; }

        [DataMember, Column("created_by"), Display(Name = "CreatedBy", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public int? CreatedBy { get; set; }

        [DataMember, Column("created_when"), Display(Name = "CreatedWhen", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public DateTime? CreatedWhen { get; set; }

        [DataMember, Column("updated_by"), Display(Name = "UpdatedBy", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public int? UpdatedBy { get; set; }

        [DataMember, Column("updated_when"), Display(Name = "UpdatedWhen", ResourceType = typeof (Resources.PsTimeAttMonthlyResource))]
        public DateTime? UpdatedWhen { get; set; }
        
        [DataMember]
        public virtual Employee Employee { get; set; }

        [DataMember, NotMapped]
        public List<PsTimeAttSummary> PsTimeAttSummaries { get; set; }
        
        public void CalNotWorkingDayCount()
        { 
           NotWorkingDayCount = (PlanWorkingDayCount ?? 0) - (ActualWorkingDayCount ?? 0) - (ValidAbsenceDayCount ?? 0);
          
        }

        public PsTimeAttendanceMonthly()
        {
            PsTimeAttSummaries = new List<PsTimeAttSummary>();
        }

    }
}